package com.lucy.rabc.provider;

import com.lucy.common.loader.LoginNameLoader;
import com.lucy.common.redis.RedisCache;
import com.lucy.rabc.entity.SysUser;
import com.lucy.rabc.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author kindear
 * 用户名获取实现
 */
@Primary
@Service
public class LoginNameProvider implements LoginNameLoader {

    private final static String LOGIN_KEY = "login_name:";

    @Autowired
    SysUserService userService;

    @Autowired
    RedisCache redisCache;

    @Override
    public String load(Long loginId) {

        Optional<SysUser> userOp = userService.getOne(loginId);
        if (!userOp.isPresent()){
            return null;
        }
        SysUser user = userOp.get();
        return user.getNickName();
    }
}
